#!/bin/bash
set -e

DEFAULT_CONFIG_PATH="configs/cls_triple.yml"
CONFIG_PATH="${1:-$DEFAULT_CONFIG_PATH}"

# Accelerate launch configuration
NUM_PROCESSES=1
MIXED_PRECISION="bf16" # Supported values: "no", "fp16", "bf16"

# --- Validation ---
if [ ! -f "$CONFIG_PATH" ]; then
    echo "Error: Config file not found at '$CONFIG_PATH'"
    exit 1
fi

# --- Execution ---
echo "Starting training with the following configuration:"
echo "  - Config File: $CONFIG_PATH"
echo "  - Number of Processes: $NUM_PROCESSES"
echo "  - Mixed Precision: $MIXED_PRECISION"
echo "----------------------------------------------------"

# Launch the training using accelerate.
# The --config argument is passed to the train.py script.
accelerate launch --num_processes ${NUM_PROCESSES} \
--mixed_precision ${MIXED_PRECISION} \
/home/tfj/code/py/cv/image_retrieval/train_triple.py --config "$CONFIG_PATH" 

echo "----------------------------------------------------"
echo "Training finished."
